<template>
  <a-popconfirm
      :title="title"
      @confirm="handleSubmit"
      okText="是"
      cancelText="否"
  >
    <a href="#" :disabled="disabled">租用车辆</a>
  </a-popconfirm>
</template>

<script>

import {addRide} from "@/api/bike/ride";

let that

export default {
  props: {
    station: {
      type: Object,
      require: true,
    },
    bikeId: {
      type: Number,
      require: true,
    },
    bikeNumber: {
      type: String,
      require: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data () {
    return {
      title: '确定要租用 ' + this.bikeNumber + ' 这辆自行车吗',
    }
  },
  watch: {
    bikeNumber (val) {
      this.title = '确定要租用' + val + '这辆自行车吗'
    },
  },
  beforeCreate () {
    that = this
  },
  created () {
  },
  methods: {
    handleSubmit () {
      let ride = {
        bikeId: this.bikeId,
        rideType: 0,
        stationId: this.station.stationId,
        stationName: this.station.stationName,
      }
      addRide(ride)
          .then(() => {
            this.$message.success('租用成功')
            this.$emit('success')
          }).catch(err => {
        this.$message.error(err.result || '操作失败！')
      })
    }
  }
}
</script>
